﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Webdisk;

namespace Webdisk_New
{
	public partial class Insert : Form
	{
		public Insert()
		{
			InitializeComponent();
            SetClassLong(this.Handle, GCL_STYLE, GetClassLong(this.Handle, GCL_STYLE) | CS_DropSHADOW);

        }

        //设置窗口外阴影
        private const int CS_DropSHADOW = 0x20000;
        private const int GCL_STYLE = (-26);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int SetClassLong(IntPtr hwnd, int nIndex, int dwNewLong);
        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        public static extern int GetClassLong(IntPtr hwnd, int nIndex);


        private void pictureBox1_MouseEnter(object sender, EventArgs e)//确认经过
        {
            pictureBox_Sub.Image = imageList1.Images[1];
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)//确认离开
        {
            pictureBox_Sub.Image = null;
        }

        private void pictureBox2_MouseEnter(object sender, EventArgs e)//取消经过
        {
            pictureBox_Cancel.Image = imageList1.Images[0];
        }

        private void pictureBox2_MouseLeave(object sender, EventArgs e)//取消离开
        {
            pictureBox_Cancel.Image = null;
        }

        private void pictureBox1_Click(object sender, EventArgs e)//确认点击
        {
            if (loginName == null || loginPass == null)
            {
                MessageBox.Show("用户名或密码不能为空！", "输入提示");
            }
            else
            {
                DialogResult result;
                result = MessageBox.Show("确认添加用户？", "输入提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                if (result == DialogResult.OK)
                {
                    string name = loginName.Text;
                    string pass = loginPass.Text;
                    string admin = "";
                    if (radioButton_user.Checked)
                    {
                        admin = "false";
                    }
                    else
                    {
                        admin = "true";
                    }
                    DBHelper.ExecuteNonQuery(string.Format("insert into userInfo(loginName,loginPass,StartTime,isadmin) values('{0}','{1}',GETDATE(),'{2}')", name, pass, admin));
                    MessageBox.Show("添加成功", "输入提示");
                }
                else
                {
                    MessageBox.Show("添加失败", "输入提示");
                }
            }
        }

        private void pictureBox2_Click(object sender, EventArgs e)//取消点击
        {
            loginName.Clear();
            loginPass.Clear();
            radioButton_user.Checked = false;
            radioButton_Adm.Checked = false;
        }
      
        private void pictureBox3_Click(object sender, EventArgs e)//最小化点击
        {
            this.WindowState = FormWindowState.Minimized;//最小化窗体
        }
        private void pictureBox4_Click(object sender, EventArgs e)//关闭点击
        {
            Close();
        }
        private void pictureBox3_MouseEnter(object sender, EventArgs e)//最小化经过
        {
            pictureBox_min.Image = imageList2.Images[1];
        }

        private void pictureBox3_MouseLeave(object sender, EventArgs e)//取消离开
        {
            pictureBox_min.Image = null;
        }

        private void pictureBox4_MouseEnter(object sender, EventArgs e)//关闭经过
        {
            pictureBox_Close.Image = imageList2.Images[0];
        }

        private void pictureBox4_MouseLeave(object sender, EventArgs e)//关闭离开
        {
            pictureBox_Close.Image = null;
        }
        //下面两个事件实现了窗口的拖动
        private Point mPoint;//坐标
        private void Insert_MouseDown_1(object sender, MouseEventArgs e)
        {
            mPoint = new Point(e.X, e.Y);
        }

        private void Insert_MouseMove_1(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                this.Location = new Point(this.Location.X + e.X - mPoint.X, this.Location.Y + e.Y - mPoint.Y);
            }
        }

        private void Insert_Load(object sender, EventArgs e)
        {

        }

        private void Insert_FormClosing(object sender, FormClosingEventArgs e)
        {
            Type.AnimateWindow(this.Handle, 300, Type.AW_BLEND | Type.AW_HIDE);//设置窗口淡出

        }

		private void radioButton_Adm_CheckedChanged(object sender, EventArgs e)
		{

		}
	}
}
